<template>
  <!--退卡提交页面-->
  <div class="tuikatijiao">
    <div class="search">
      <input type="text" placeholder="搜索" v-model="content">
      <img src="../../assets/search.png" width="16" @click="goSearch()">
    </div>
    <div class="page-infinite-wrapper" ref="wrapper" :style="{ height: wrapperHeight + 'px' }">
      <wv-group
        v-infinite-scroll="getList"
        infinite-scroll-disabled="loading"
        infinite-scroll-distance="10"
      >
        <ul class="list">
          <li v-for="item in accountGoodsList">
            <ul>
              <li>{{item.mobile}} <span v-if="item.userName!=''">{{item.userName}}</span>
                <span v-else>{{item.accountPhone}}</span>
                <wv-button type="default" :mini="true" class="lookdetail" @click="goShowBackCard(item)">申请退卡</wv-button>
              </li>
              <li>{{item.goodsName}}
                <wv-button type="default" :mini="true" class="lookdetail" @click="showNowRefund(item)">现办现退</wv-button>
              </li>
              <li>
                <p>开卡时间：{{item.buyDate}}</p>
                <span>有效</span>
              </li>
              <li>
                <p v-if="item.payType=='PAY_WX'"><img src="../../assets/weixin.png" alt="" width="15">讯联微信</p>
                <p v-if="item.payType=='PAY_WX_YINLIAN'"><img src="../../assets/weixin.png" alt="" width="15">银联微信</p>
                <p v-if="item.payType=='PAY_UNDERLINE'">
                  <img :src="item.paywayIcon | imgPathFilter" alt="" width="15">{{item.paywayName}}
                </p>
                <span><img src="../../assets/yuangong.png" alt="" width="15">{{item.employeeName}}</span>
              </li>
            </ul>
          </li>
        </ul>
      </wv-group>
    </div>

    <div class="model1" v-show="isNowRefundVisible">
      <div class="bg1"></div>
      <div class="modelContent1">
        请确认该会员是否要现办先退，确认后支付金额原路返还?
        <p class="btn1">
          <button tag="button" @click="goNowRefundBackCard(params)">确认</button>
          <button @click="isNowRefundVisible=false">取消</button>
        </p>
      </div>
    </div>

    <div class="model" v-show="isVisible">
      <div class="bg"></div>
      <div class="modelContent">
        <wv-group class="textarea">
          <wv-textarea placeholder="退卡原因（此项必填）" :rows="5" v-model="refundReason" :max-length="500"></wv-textarea>
        </wv-group>
        <wv-group class="textarea">
          <wv-textarea placeholder="退卡说明（此项必填如已沟通好，把退款金额、打款账户等在此说明）" :rows="5" v-model="remark"
                       :max-length="500"></wv-textarea>
        </wv-group>
        <p class="btn">
          <wv-button type="default" :mini="true" @click="goBackCard(params)">提交</wv-button>
          <wv-button type="default" :mini="true" @click="isVisible=false">取消</wv-button>
        </p>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import {getCanTuikaData, tuikaSub, nowRefundTuikaSub} from '../../../test/unit/http'
  import {Toast} from 'we-vue'

  export default {
    name: '',
    props: {},
    data() {
      return {
        isVisible: false,
        isNowRefundVisible: false,
        accountGoodsList: [],
        content: '',
        wrapperHeight: 0,
        page: 1,
        rows: 5,
        loading: false,
        pages: 0,
        totalNum: 0,
        remark: '',
        refundReason: '',
        params: {}
      };
    },
    methods: {
      getList() {
        let params = {};
        params['queryContent'] = this.content;
        params['page'] = this.page;
        params['rows'] = this.rows;
        this.getData(params);
      },
      goSearch() {
        this.accountGoodsList = [];
        this.page = 1;
        this.getList();
      },
      getData(params) {
        this.loading = true;
        getCanTuikaData(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            let data = res.object;
            let list = data.rows;
            let pages = data.pages;
            this.pages = pages;
            let page = data.page;
            this.page = page;
            let totalNum = data.totalNum;
            this.totalNum = totalNum;
            if (list.length > 0) {
              this.accountGoodsList = this.accountGoodsList.concat(list);
            }
            if (this.page < this.pages) {
              this.page++;
              this.loading = false
            } else {
              this.loading = true
            }
          } else {
            Toast.text(res.info);
          }
        })
      },
      goBackCard(params) {
        params['remark'] = this.remark;
        params['refundReason'] = this.refundReason;
        console.info(params);
        if (this.$myUtils.isNull(params.refundReason)) {
          Toast.text("退卡原因必填");
          return;
        }
        if (this.$myUtils.isNull(params.remark)) {
          Toast.text("退卡说明必填");
          return;
        }
        tuikaSub(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            Toast.success('提交成功');
            this.isVisible = false;
            this.$router.push({path: 'tuika'});
          } else {
            Toast.text(res.info);
          }
        })
      },
      goNowRefundBackCard(params) {
        nowRefundTuikaSub(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            Toast.success('提交成功');
            this.isNowRefundVisible = false;
            this.$router.push('tuika')
          } else {
            Toast.text(res.info);
          }
        })
      },
      goShowBackCard(accountGoods) {
        this.isVisible = true;
        let params = {
          accountGoodsId: accountGoods.accountGoodsId,
          vipCardNo: accountGoods.vipCardNo,
          userId: accountGoods.accountId,
          uesrName: accountGoods.uesrName,
          uesrPhone: accountGoods.uesrPhone,
          airportId: accountGoods.airportId
        };
        this.params = params;
      },
      showNowRefund(accountGoods) {
        this.isNowRefundVisible = true;
        let params = {
          accountGoodsId: accountGoods.accountGoodsId,
          vipCardNo: accountGoods.vipCardNo,
          userId: accountGoods.accountId,
          uesrName: accountGoods.uesrName,
          uesrPhone: accountGoods.uesrPhone,
          airportId: accountGoods.airportId,
          remark: ""
        };
        this.params = params;
      }
    },
    created() {
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    /*border-radius: 8px;*/
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 2;
    width: 100%;
    padding: 15px 0;

    .textarea .weui-cell {
      border: 1px solid #ddd;
      border-radius: 5px;
      background-color: #f8f8f8;
      width: 81%;
      margin: auto;
    }

    li:first-child {
      margin-bottom: 10px;
    }

    .btn {
      text-align: right;
      padding: 15px 15px 0;

      button {
        height: 30px;
        line-height: 30px;
        color: #fff;
        width: 75px;
        border-radius: 25px;
      }

      button:last-child {
        background-color: #ccc;
        border: 1px solid #ccc;
        color: #fff;
      }

      button:first-child {
        background-color: #f98e3c;
        margin-right: 20px;

      }
    }
  }

  .bg1 {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model1 .modelContent1 {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: left;

    img1 {
      position: absolute;
      right: 10px;
      top: 10px
    }

    .btn1 {
      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
        margin-top: 25px;
      }

      :last-child {
        background-color: #aaa;

      }

      :first-child {
        background-color: #f98e3c;
        margin-right: 20px;

      }
    }

  }

  .search {
    position: relative;
    width: 95%;
    margin: 10px auto;

    input {
      width: 90%;
      border: 1px solid #eee;
      box-shadow: 0 3px 4px rgba(17, 17, 17, 0.05);
      border-radius: 7px;
      height: 43px;
      line-height: 43px;
      padding: 10px;
      color: #111;
    }

    img {
      position: absolute;
      right: 20px;
      top: 27px;
    }
  }

  .list {
    > li {
      margin: 15px 10px;
      text-align: left;
      border-bottom: 1px solid #ddd;

      li {
        margin-bottom: 10px;
      }

      li:first-child {
        font-size: 16px;
        color: #111;
        font-weight: 700;

        span {
          color: #999;
          margin-left: 10px;
          font-size: 12px;
        }

        button {
          float: right;
          display: inline-block;
        }

        .lookdetail {
          background-color: #fff;
          border: 1px solid #f98e3c;
          color: #f98e3c;
        }
      }

      li:nth-child(2) {
        line-height: 35px;
        height: 35px;
        color: #111;
        font-size: 15px;
        font-weight: 600;

        button {
          float: right;
        }

        .lookdetail {
          background-color: #fff;
          border: 1px solid #f98e3c;
          color: #f98e3c;
        }
      }

      li:nth-child(3), li:last-child {
        font-size: 12px;
        color: #666;
        display: flex;
        text-align: left;

        p {
          flex: 1;
        }

        span {
          font-size: 15px;
          color: #f98e3c;
        }
      }

      li:last-child {
        img {
          vertical-align: middle;
          margin-right: 5px;
        }

        span {
          color: #f98e3c;
          font-size: 15px;
          text-align: right;
        }
      }
    }

    > li:last-child {
      border-bottom: none;
    }

  }
</style>


